package cn.pet.service.manage.entity.api;

import cn.pet.service.manage.config.StatusCode;

import java.io.Serializable;

/**
 * 描述
 */
public class Result<T> implements Serializable {
    private Integer code;//返回码
    private String message;//返回消息
    private T data;//返回数据

    public static <R> Result<R> ok(String msg, R data) {
        Result<R> tResult = new Result<>();
        tResult.setCode(StatusCode.OK);
        tResult.setMessage(msg);
        tResult.setData(data);
        return tResult;
    }

    public static <R> Result<R> ok(String msg) {
        Result<R> tResult = new Result<>();
        tResult.setCode(StatusCode.OK);
        tResult.setMessage(msg);
        return tResult;
    }

    public static <R> Result<R> error(String message, R data) {
        Result<R> tResult = new Result<>();
        tResult.setCode(StatusCode.ERROR);
        tResult.setMessage(message);
        tResult.setData(data);
        return tResult;
    }

    public static <R> Result<R> error(String message) {
        Result<R> tResult = new Result<>();
        tResult.setCode(StatusCode.ERROR);
        tResult.setMessage(message);
        return tResult;
    }

    public static <R> Result<R> error(Integer code,String message) {
        Result<R> tResult = new Result<>();
        tResult.setCode(code);
        tResult.setMessage(message);
        return tResult;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
